-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: generate bundles for "worker" style environement #2819
Conversation
🦋 Changeset detectedLatest commit: ea22839 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@mitchellhamilton I fixed the spelling issue and only added the "worker" condition to packages that need it. I was sure that the spelling issue was the reason that the extra fields were not being generated. However, I have run I want to be respectful of your time so I'll keep trying to debug on my end. Thanks again for all your help with this! |
You might not be running preconstruct from the root of the repo? (As in, you need to run it from the root of the repo) |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ea22839:
|
@mitchellhamilton I deleted |
Looks great 😃. Question: have you only generated |
I'm open to making this change if others agree that it would be useful. The reason I didn't initially include it is because it doesn't not actually change anything. Preconstruct builds (and therefore emotion builds) specifically target bundlers and most bundlers know how to read from the I imagine that someday, preconstruct will be extended to support Node ESM (ie the |
Your first paragraph makes sense to me! I'm not 100% sure what you mean by:
I tested your changes and came up with this patch: diff --git a/packages/react/package.json b/packages/react/package.json
index de9470c1..7dcf755f 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -8,7 +8,8 @@
},
"exports": {
".": {
- "module": {
+ "types": "./types/index.d.ts",
+ "import": {
"worker": "./dist/emotion-react.worker.esm.js",
"browser": "./dist/emotion-react.browser.esm.js",
"default": "./dist/emotion-react.esm.js"
@@ -16,7 +17,8 @@
"default": "./dist/emotion-react.cjs.js"
},
"./jsx-runtime": {
- "module": {
+ "types": "./types/jsx-runtime.d.ts",
+ "import": {
"worker": "./jsx-runtime/dist/emotion-react-jsx-runtime.worker.esm.js",
"browser": "./jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js",
"default": "./jsx-runtime/dist/emotion-react-jsx-runtime.esm.js"
@@ -24,7 +26,7 @@
"default": "./jsx-runtime/dist/emotion-react-jsx-runtime.cjs.js"
},
"./_isolated-hnrs": {
- "module": {
+ "import": {
"worker": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.worker.esm.js",
"browser": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.browser.esm.js",
"default": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.esm.js"
@@ -32,13 +34,15 @@
"default": "./_isolated-hnrs/dist/emotion-react-_isolated-hnrs.cjs.js"
},
"./jsx-dev-runtime": {
- "module": {
+ "types": "./types/jsx-dev-runtime.d.ts",
+ "import": {
"worker": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.worker.esm.js",
"browser": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.browser.esm.js",
"default": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.esm.js"
},
"default": "./jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.cjs.js"
},
+ "./macro": "./macro.js",
"./package.json": "./package.json"
},
"types": "types/index.d.ts", Description of changes:
Assuming what I did is correct, these same changes will need to be made to the other |
@srmagura preconstruct (and therefore emotion) purposely does not support the node specific I'm not a maintainer of emotion so I can not speak for the group but my understanding is that emotion will likely not support ESM node (ie the |
We should make it possible for emotion to be imported by Node ESM (including with TypeScript's |
@mitchellhamilton what would that look like? Do you feel like that should be included with this PR? Should I manually add the “imports” and “types” conditions to all packages? |
Yes - not doing so would be a regression from the current behavior
We should not use the Rather than adding the types condition (because otherwise you'd have to duplicate all of the conditions because @Andarist do you have any thoughts on the breaking change-ness of adding the exports field for emotion? Should we just not care if people are importing stuff from dist? Should we keep the files in |
I'm not an expert on this stuff but here's my 2 cents:
It seems fine to do this as a minor version bump. AFAIK we've never documented importing stuff directly from
I vote for killing the The export * from '..'; |
This might be hard to pull off here because dtslint setup requires those types to live in its own directory. Unless we reexport what is in
I think that all of that should be OK to do. We never made any guarantees about the internal file structure. So we only need to support what has been documented etc.
Yeah, this was just to make |
This is what I was thinking we would do - though probably not include them in the exports field |
You might need to use .mjs extensions for esm for better compatibility, see https://github.com/sheremet-va/dual-packaging |
# Conflicts: # package.json # yarn.lock
I've pushed some changes to this branch. I think that the only leftover to fix is the Are there any other blockers that come to your mind @mitchellhamilton ? |
@mitchellhamilton @Andarist FWIW, I have tested this version of emotion with Cloudflare workers specifically and it works with no issues! I think we may be ready to merge! 🎉 |
Yep, I'm a little bit scared of this PR but I'll be ripping this bandaid off soon. |
What:
This is PR uses a
hopefully soon-to-be-releasednewly released version of preconstruct that support building "worker" compatible builds. The primary use-case for this is to support Cloudflare workers.Why:
fixes #2554
fixes #2730
fixes #2413
How:
I've made changes to each package in the monorepo and extended the package.json to include an "exports" field with custom conditionals for "browser" and "worker".
Checklist: